package com.fenyin.samples.study.regex;  

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 *@Title:  java正则表达式
 *@Description:  正则表达式简单实例
 *@Author:fengzhichao  
 *@Since:2012-8-21  
 *@Version:1.1.0
 */
public class SimpleRegexCase {
	
	public static void main(String[] args){
//		//IP地址匹配规则
//		String regex = "((2[0-4]\\d|25[0-5]|[01]?\\d\\d?)\\.){3}(2[0-4]\\d|25[0-5]|[01]?\\d\\d?)";
//		String inputString = "127.0.0.1";
//		//匹配模式类
//		Pattern pattern = Pattern.compile(regex);
//		//匹配类
//		Matcher matcher = pattern.matcher(inputString);
//		
//		if(matcher.matches()){
//			System.out.println("匹配成功");
//		}else{
//			System.out.println("匹配失败");
//		}
		
//		向后引用
//		String regex = "<\\w+>.*?</\\w+>";
//		String regex = "<(\\w+)>.*?</\\1>";
//		String inputString = "<name>fengzhichao</fname><mail>fengzhichao@163.com</mail>";
//	
//		Pattern pattern = Pattern.compile(regex);
//		Matcher matcher = pattern.matcher(inputString);
//		while(matcher.find()){
//			System.out.println(matcher.group());
//		}
		
//		分组
//		String regex = "(\\w+)@(\\w+\\.\\w+)";
//		String input = "fengzhichao@58.com";
//		Pattern pattern = Pattern.compile(regex);
//		Matcher matcher = pattern.matcher(input);
//		matcher.matches();
//		System.out.println("groupcount:"+matcher.groupCount());
//		System.out.println("group(0):"+matcher.group(0));
//		System.out.println("group(1):"+matcher.group(1));
//		System.out.println("group(2):"+matcher.group(2));
		
		
	}
	
}
